package com.xdan.monitoringservice.thread;

import com.xdan.monitoringservice.config.MyConfig;
import com.xdan.monitoringservice.listener.ListenerService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import javax.annotation.Resource;

@Configuration
public class CustomSchedulingConfigurer implements SchedulingConfigurer {

    @Resource
    private MyConfig myConfig;

    @Resource
    private ListenerService listenerService;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addFixedRateTask(() -> listenerService.listenerInstanceTypes(), myConfig.getListeningInterval() * 1000);
    }
}